const repairService = require('../service/repairService.js')
const auth = require('../middleware/auth.js')
const code = require('../common/code.js')
const KoaRouter = require('koa-router')

const router = new KoaRouter()

router.get('/repair/:id', auth(['EDP']), async ctx => {
    ctx.body = code.getCode(code.SUCCESS, null, await repairService.getOne(ctx.params.id))
})

router.post('/repair', auth(['EDP']), async ctx => {
    ctx.body = code.getCode(code.SUCCESS, null, await repairService.insert(ctx.request.body, ctx.session.user.store_id))
})

router.put('/repair/:id', auth(['EDP']), async ctx => {
    ctx.body = code.getCode(code.SUCCESS, null, await repairService.update(ctx.params.id, ctx.request.body, ctx.session.user.store_id))
})

router.delete('/repair/:id', auth(['EDP']), async ctx => {
    ctx.body = code.getCode(code.SUCCESS, null, await repairService.del(ctx.params.id))
})
module.exports = router
